package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.domain.customer.CustomerDO;
import com.qk.dto.customer.CustomerDTO;
import com.qk.dto.customer.CustomerQueryDTO;
import com.qk.entity.Customer;
import com.qk.management.service.CustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@Slf4j
@RestController
@RequestMapping("/customers")
@SuppressWarnings("all")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    @PutMapping
    public Result updateCustomer(@RequestBody Customer customer){
        log.info("修改客户信息为：{}",customer);
        customerService.updateById(customer);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Customer customer = customerService.getById(id);
        return Result.success(customer);
    }

    @GetMapping
    public Result page(CustomerQueryDTO dto){
        PageResult<CustomerDO> list = customerService.selectByPage(dto);
        return Result.success(list);
    }
    @PostMapping
    public Result addCustomer(@RequestBody CustomerDTO dto){
        customerService.addCustomer(dto);
        return Result.success();
    }
}
